#include<bits/stdc++.h>
#define ll long long
#define un unsigned
#define INF 214748364719260817ll
using namespace std;
ll T;
set<ll>s;
ll sum;
int main()
{
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>T;
	for(ll t=1;t<=T;++t)
	{
		ll x;
		cin>>x;
		if(s.find(x)!=s.end())
			s.erase(s.find(x)),sum-=x;
		else s.insert(x),sum+=x;
		if(s.size()<=1)
		{
			cout<<0<<'\n';continue;
		}
		if(T<=1000)
		{
			ll l=0,r=0;
			auto vl=s.begin(),vr=s.end();
			--vr;
			ll res=0;
			for(ll i=1;i<=s.size();++i)
			{
				ll nl=max(r,l+*vl),nr=r+*vr;
				res+=nr-nl;
				l=l+*vl;r=r+*vr;
				++vl;--vr;
			}
			cout<<res<<'\n';
		}
		else
			cout<<sum-*s.begin()*2<<'\n';
	}
}
